﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace StateManager
{
    abstract class GenericScreenCode
    {
        
        private SManager sManager;

        public SManager SManager
        {
            get { return sManager; }
            set { sManager = value; }
        }

        

        public bool IsPopup
        {
            get { return isPopup; }
            protected set { isPopup = value; }
        }

        bool isPopup = false;

        public PlayerIndex? ControllingPlayer
        {
            get { return controllingPlayer; }
            internal set { controllingPlayer = value; }
        }

        PlayerIndex? controllingPlayer;


        public TimeSpan TransitionOnTime
        {
            get { return transitionOnTime; }
            protected set { transitionOnTime = value; }
        }

        TimeSpan transitionOnTime = TimeSpan.Zero;

        public bool IsExiting
        {
            get { return isExiting; }
            protected internal set { isExiting = value; }
        }

        bool isExiting = false;


        public ScreenState ScreenState
        {
            get { return screenState; }
            protected set { screenState = value; }
        }

        ScreenState screenState = ScreenState.Active;

        public bool IsActive
        {
            get
            {
                return !NotFocused && screenState == ScreenState.Active;
            }
        }

        bool NotFocused;

        public GenericScreenCode()
        {
        }

        public virtual void HandleInput(Input input) { }


        public virtual void Update(GameTime gameTime, bool setFocus,
                                                     bool coveredByOtherScreen)
        {
            NotFocused = setFocus;

            if (isExiting)
            {  
                sManager.RemoveScreen(this);
            }
            else if (coveredByOtherScreen)
            {
 
                screenState = ScreenState.Hidden;
            }
            else
            {
                screenState = ScreenState.Active;

            }
        }

        public virtual void LoadContent() { }

        public virtual void LoadContent(char c) { }
        // for use with the multiplayer game

        public virtual void UnloadContent() { }

        // method to get the screen to draw
        public virtual void Draw(GameTime gameTime) { }

        public void ExitScreen()
        {
            sManager.RemoveScreen(this);
        }

    }
}
